package javaweb.sevice.impl;

import javaweb.mapper.DeptMapper;
import javaweb.pojo.Dept;
import javaweb.sevice.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/*
*
* 定义业务逻辑
*
* */
@Service
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptMapper deptMapper;

    @Override
    public List<Dept> findAllDept() {

        List<Dept> list = deptMapper.findAllDept();

        return list;
    }

    @Override
    public void deleteDeptByID(String id) {
        //调用Mapper接口
        deptMapper.deleteDeptByID(id);
    }

    @Override
    public void insertDept(Dept dept) {
        //补全dept类的对象
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insertDept(dept);
    }

    @Override
    public Dept findById(Integer id) {
       Dept dept = deptMapper.findById(id);
       return dept;
    }

    @Override
    public void updateDept(Dept dept) {
        //补全dept类的对象
        dept.setUpdateTime(LocalDateTime.now());

        deptMapper.updateDept(dept);
    }
}
